/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Random;

/**
 * <p>Project: javase - Arr4
 * <p>Powered by webrx On 2021-11-26 14:39:52
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Arr4 {
    public static void main(String[] args) {
        int[] ns = new int[10];
        Random rand = new Random();
        for (int i = 0; i < ns.length; i++) {
            ns[i] = rand.nextInt(100) + 1;
        }
        print(ns);

        //冒泡
        for (int m = 0; m < ns.length; m++) {
            for (int n = 0; n < ns.length - m - 1; n++) {
                //> 升序  if (ns[n] > ns[n + 1]) {
                //< 降序  if (ns[n] < ns[n + 1]) {
                //乱序    if (rand.nextBoolean()) {
                if (rand.nextBoolean()) {
                    int t = ns[n];
                    ns[n] = ns[n + 1];
                    ns[n + 1] = t;
                }


            }
        }

        print(ns);
    }

    public static void print(int[] arr) {
        System.out.println(Arrays.toString(arr));
    }
}
